package com.designpattern.createpattern.demo05;

/**
 * @description:所谓原型模式，主要就是为了拷贝对象，而不是重新创建对象。
 * 而拷贝的对象，可以是浅拷贝，也可以是深拷贝。
 * 浅拷贝：只拷贝基本类型的属性，不会拷贝引用的对象。
 * 深拷贝：拷贝基本类型的属性，并且拷贝引用的对象。
 */
public class Main {
    public static void main(String[] args) {
        Pig pig = new Pig();
        pig.setAge(10);
        pig.setColor("black");
        pig.setSex("female");
        System.out.println(pig.toString()+" pig="+pig.hashCode());
        Pig pig1 = (Pig) pig.clone();
        System.out.println(pig1.toString()+" pig1="+pig1.hashCode());
        Pig pig2 = (Pig) Utils.deepCopy(pig);
        System.out.println(pig2.toString()+" pig2="+pig2.hashCode());

        Sheep sheep = new Sheep();
        sheep.setName("tom");
        sheep.setAge(10);
        sheep.setColor("white");
        sheep.setSex("male");
        sheep.setPig(pig);
        System.out.println(sheep.toString()+" sheep="+sheep.hashCode());
        Sheep sheep1 = (Sheep) Utils.deepCopy(sheep);
        System.out.println(sheep1.toString()+" sheep1="+sheep1.hashCode());
        Sheep sheep2 = Utils.deepCopy2(sheep);
        System.out.println(sheep2.toString()+" sheep2="+sheep2.hashCode());
    }
}
